<?


Class CategoryModule{
    var $_connect;
    var $error;
    function CategoryModule() {
        $this->_connect = new Dataconnection();
    }
    function getCategory($id){
        $SQLCommand="
        select * 
        from `categorys` 
        where `delete` is null
            and `id`='$id'
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $result=array();
        if($data!=null ){
            $result=$data->fetch_array();
            return $result;
        }
        return null;
    }
    function getCategorys(){
        $SQLCommand="
        select * 
        from `categorys` 
        where `delete` is null 
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $result=array();
        if($data!=null ){
            while ($row=$data->fetch_array())
                array_push($result, $row);
            return $result;
        }
        return null;
    }
    function insertCategory($name,$lv){
        $SQLCommand="
        INSERT 
            `categorys`(
                        `name`,`level`,`insert`
            )
            VALUE(
                        '$name','$lv',now()
            )
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function updateCategory($name,$lv,$id){
        //$name=  str_replace("'", htmlentities("'",ENT_QUOTES,'utf-8'), $name);
        //$brief=  str_replace("'", htmlentities("'",ENT_QUOTES,'utf-8'), $brief);
        //$des=  EndcodeStr($des);//str_replace("'", htmlentities("'",ENT_QUOTES,'utf-8'), $des);
        $SQLCommand="
        UPDATE 
            `categorys`
        SET `name`='$name',`level`='$lv',`update`=now()
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function deleteCategory($id){
        //$name=  str_replace("'", htmlentities("'",ENT_QUOTES,'utf-8'), $name);
        //$brief=  str_replace("'", htmlentities("'",ENT_QUOTES,'utf-8'), $brief);
        //$des=  EndcodeStr($des);//str_replace("'", htmlentities("'",ENT_QUOTES,'utf-8'), $des);
        $SQLCommand="
        UPDATE 
            `categorys`
        SET `delete`=now()
        WHERE `id`='$id'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
}
?>